<template>
  <div class="wrapper">
    <div class="content-wrapper">
      <div class="orderHeader">
        <div class="orderSearch">
          <el-form ref="form" :model="searchParams" :inline="true">
            <el-form-item label="CAPA号">
              <el-input
                v-model="searchParams.capa_no"
                clearable
                placeholder="请输入CAPA号"
              />
            </el-form-item>
            <el-form-item label="运单号">
              <el-input
                v-model="searchParams.waybill_no"
                clearable
                placeholder="请输入运单号"
              />
            </el-form-item>

            <!-- <el-form-item label="培训名称">
                            <el-input v-model="searchParams.name" clearable placeholder="请填写培训名称" />
                        </el-form-item> -->
            <!-- <el-form-item label="培训时间">
                            <el-date-picker @change="handleTimeChange" v-model="timeRange" type="datetimerange"
                                :picker-options="pickerOptions" value-format="timestamp" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期" align="right">
                            </el-date-picker>
                        </el-form-item>-->
            <el-form-item>
              <el-button
                id="go_search"
                type="primary"
                icon="el-icon-search"
                data-tracker="P10-3"
                @click="handleSearch"
                >查询
              </el-button>
              <el-button
                type="primary"
                plain
                icon="el-icon-refresh"
                data-tracker="P10-4"
                @click="handleReset"
                >重置
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="actions" style="margin-bottom: 10px">
        <div class="left">
          <el-button type="primary" plain size="mini" @click="handleAdd"
            >新增</el-button
          >
          <el-button type="primary" plain size="mini" @click="handleDel"
            >删除</el-button
          >
        </div>
        <div class="right">
          <el-pagination
            background
            small
            :current-page="paginations.pageIndex"
            :page-sizes="paginations.pageSizes"
            :page-size="paginations.pageSize"
            :layout="paginations.layout"
            :total="paginations.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        border
        stripe
        align="center"
        @selection-change="handleSelectionChange"
        :max-height="maxheight"
      >
        <el-table-column type="selection" width="45"> </el-table-column>
        <el-table-column
          prop=""
          label="序号"
          width="50"
          type="index"
        ></el-table-column>
        <el-table-column prop="capa_no" label="CAPA号" width="180">
        </el-table-column>
        <el-table-column prop="waybill_no" label="运单号" width="180">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="180">
          <template slot-scope="scope">
            {{
              [
                "投诉处理与报告",
                "评估影响",
                "纠正与预防措施",
                "主管复核",
                "生效",
              ][scope.row.status]
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="occur_time"
          label="事故/投诉发生日期"
          width="180"
        >
          <template slot-scope="scope">
            <span v-time="scope.row.occur_time"></span>
          </template>
        </el-table-column>
        <el-table-column prop="report_user_id_name" label="报告人" width="180">
        </el-table-column>
        <el-table-column prop="problem_explain" label="问题说明" width="180">
        </el-table-column>
        <el-table-column
          prop="duty_area_leader_id_name"
          label="责任地区负责人"
          width="180"
        >
        </el-table-column>

        <el-table-column
          prop="quality_control_leader_id_name"
          label="质量控制负责人"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="corrective_user_id_name"
          label="纠正措施执行人"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="prevent_user_id_name"
          label="预防措施执行人"
          width="180"
        >
        </el-table-column>
        <!-- <el-table-column prop="plan_training_time" label="培训时间" width="180">
                <template slot-scope="scope">
                    <span v-time="scope.row.plan_training_time"></span>
                </template>
            </el-table-column> -->
        <el-table-column
          prop=""
          fixed="right"
          align="center"
          label="操作"
          width="160"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              plain
              size="mini"
              @click="handleOperation(scope.row, 'detail')"
              >详情
            </el-button>
            <el-button
              type="text"
              plain
              size="mini"
              @click="handleOperation(scope.row, 'edit')"
              >编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { CapaList, CapaDelete } from "@/api/qms";
export default {
  name: "refundReviewList",
  components: {},
  props: [],
  data() {
    return {
      maxheight: "auto",
      tableData: [],
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 200,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      checkedList: [],
      searchParams: {},
    };
  },
  mounted() {
    this.getDataList();
  },
  methods: {
    handleAdd() {
      this.mode = "add";
      this.$router.push({
        name: "capaEdit",
      });
    },
    handleDel() {
      if (this.checkedList.length === 0) {
        this.$message({
          message: "请选中后进行操作",
          type: "warning",
        });
        return;
      }
      if (this.checkedList.length !== 1) {
        this.$message({
          message: "只支持单个删除！",
          type: "warning",
        });
        return;
      }
      CapaDelete({
        id: this.checkedList[0],
      }).then((res) => {
        if (res.code === 10000) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getDataList();
        }
      });
    },
    handleSearch() {
      this.paginations.pageIndex = 1;
      this.getDataList();
    },
    handleReset() {
      this.paginations.pageIndex = 1;
      this.searchParams = {};

      this.getDataList();
    },
    handleOperation(row, mode) {
      this.$router.push({
        name: "capaEdit",
        query: {
          id: row.id,
          mode,
        },
      });
    },
    handleSelectionChange(checked) {
      this.checkedList = checked.map((item) => item.id);
    },
    // 通过、驳回
    handleClickOperation(type) {
      this.reviewType = type;
      this.dialogVisible = true;
    },
    handleCloseDialog() {
      this.dialogVisible = false;
    },
    // 每页条数改变
    handleSizeChange(val) {
      this.paginations.pageSize = val;
      this.getDataList();
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.paginations.pageIndex = val;
      this.getDataList();
    },
    getDataList() {
      CapaList({
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        ...this.searchParams,
      }).then((res) => {
        this.tableData = res.data.data || [];
        if (this.tableData.length > 6) {
          //两排操作栏
          this.maxheight = document.documentElement.clientHeight - 265;
        } else {
          this.maxheight = "auto";
        }

        this.paginations.total = res.data.pagination.total;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  padding: 10px 15px;
  background-color: #fff;

  .orderHeader {
    // margin-top: 5px;
    background-color: #fff;

    .orderSearch {
      form {
        ::v-deep .el-form-item__label {
          font-size: 14px;
        }

        .el-textarea {
          width: 135px;
        }
      }
    }
  }

  .actions {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    background-color: #fff;

    .el-button + .el-dropdown,
    .el-dropdown + .el-button {
      margin-left: 10px;
    }
  }
}
</style>